﻿<Page
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:caliburn="using:Caliburn.Micro"
    x:Class="MusicExplorer.Views.GroupEditionView"
    xmlns:common="using:MusicExplorer.Common" 
    xmlns:converters="using:MusicExplorer.Converters"
    >

    <Page.Resources>
        <converters:QueryTypeToBooleanConverter x:Key="QueryTypeToBooleanConverter" />
        <converters:InvertBooleanToVisibilityConverter x:Key="InvertBooleanToVisibilityConverter" />
        <converters:UriTo100x100BitmapConverter x:Key="UriTo100x100BitmapConverter" />
    </Page.Resources>

    <Page.BottomAppBar>
        <CommandBar Height="92" IsOpen="{Binding ShowCommandBar, Mode=TwoWay}" IsSticky="True">
            <CommandBar.SecondaryCommands>
                <AppBarButton Label="Add" Icon="Add" Visibility="{Binding ShowAddButton, Converter={StaticResource BooleanToVisibilityConverter}}"
                              caliburn:Message.Attach="[Event Click] = [AddSelectedEntities]"  />
                <AppBarButton Label="Remove" Icon="Remove" Visibility="{Binding ShowRemoveButton, Converter={StaticResource BooleanToVisibilityConverter}}"
                              caliburn:Message.Attach="[Event Click] = [RemoveSelectedEntities]"  />
            </CommandBar.SecondaryCommands>
        </CommandBar>
    </Page.BottomAppBar>

    <Grid Background="{StaticResource DefaultApplicationBackground}">
        <Grid.RowDefinitions>
            <RowDefinition Height="180" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>

        <Grid x:Name="progressGrid" VerticalAlignment="Top">
            <ProgressBar IsIndeterminate="True" Height="10" />
        </Grid>

        <Grid Margin="20, 20, 0, 0">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="180" />
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Border BorderBrush="{StaticResource DefaultApplicationBorderTileBrush}" BorderThickness="1"
                            Width="150" Height="150" VerticalAlignment="Center" HorizontalAlignment="Center" >
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="150" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="150" />
                    </Grid.ColumnDefinitions>
                    <ProgressRing IsActive="{Binding UploadInProgress}"
                                  Foreground="{StaticResource DefaultApplicationForeground}" />
                    <Image Source="{Binding Image}" Stretch="UniformToFill"
                                   Visibility="{Binding UploadInProgress, Converter={StaticResource InvertBooleanToVisibilityConverter}}"
                                   HorizontalAlignment="Center" VerticalAlignment="Center" />
                </Grid>
            </Border>
            <TextBlock Text="{Binding Title}" Style="{StaticResource PageHeaderTextStyle}"
                       Foreground="{StaticResource DefaultApplicationForeground}" Grid.Column="1" VerticalAlignment="Center" />
        </Grid>

        <Grid Grid.Row="1" Margin="20">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>

            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                </Grid.RowDefinitions>

                <TextBlock Text="Name" Margin="0,-11,10,10" Style="{StaticResource DefaultApplicationGroupTitleStyle}" />

                <TextBox Text="{Binding Name, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.Row="1"
						PlaceholderText="Enter group name here" BorderBrush="{StaticResource DefaultApplicationBorderTileBrush}" />

                <!--<CheckBox Content="Display infos on home page" Foreground="{StaticResource DefaultApplicationSecondaryForeground}"
                          Margin="-3, 0, 0, 0" IsChecked="{Binding DisplayOnHomeScreen, Mode=TwoWay}" RequestedTheme="Light" Grid.Row="2" />-->

                <TextBlock Text="Query type" Margin="0,5,10,10" Grid.Row="3"
                           Style="{StaticResource DefaultApplicationGroupTitleStyle}" />
                <ToggleSwitch Foreground="{StaticResource DefaultApplicationForeground}" Margin="-5, -10, 0, 0"
                                  Style="{StaticResource DefaultToggleSwitchStyle}" Grid.Row="4"
                                  caliburn:Message.Attach="[Event Toggled] = [CheckQueryType]"
                                  IsOn="{Binding SelectedQueryType, Converter={StaticResource QueryTypeToBooleanConverter}, Mode=TwoWay}" >
                    <ToggleSwitch.OnContent>
                        Top Tracks
                    </ToggleSwitch.OnContent>
                    <ToggleSwitch.OffContent>
                        All Tracks
                    </ToggleSwitch.OffContent>
                </ToggleSwitch>

                <TextBlock Text="Image" Grid.Row="5"
                           Margin="0,-11,10,10" Style="{StaticResource DefaultApplicationGroupTitleStyle}" />

                <Grid Grid.Row="6">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="30" />
                        <ColumnDefinition Width="*" />
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="Auto" />
                    </Grid.ColumnDefinitions>

                    <TextBlock Text="Url" Margin="0,-10,10,10" Style="{StaticResource DefaultApplicationGroupTitleStyle}" FontSize="13" />
                    <TextBox Text="{Binding ImageUrl, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Grid.Column="1"
					    PlaceholderText="Url of image you want to use" Grid.Row="1" RequestedTheme="Light" />
                    <Button Content="Upload" x:Name="UploadImage" Style="{StaticResource DefaultTextButtonStyle}" Grid.Column="3"
                            Foreground="{StaticResource DefaultApplicationForeground}" Margin="10, 0, 0, 0" />
                </Grid>
                
                <Grid Grid.Row="7" Margin="0, 5, 0, 0">
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="30" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="or" Margin="0,-10,10,10" Style="{StaticResource DefaultApplicationGroupTitleStyle}" FontSize="13" />
                    <Grid Grid.Column="1">
                        <TextBox Text="{Binding ImageSearchTerms, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                                 Grid.Column="1" PlaceholderText="Search image over the web" RequestedTheme="Light" />
                        <ProgressRing IsActive="{Binding SearchImageInProgress}" Grid.Column="2" HorizontalAlignment="Right"
                                      Foreground="{StaticResource DefaultApplicationForeground}" Margin="0, 0, 30, 0" VerticalAlignment="Center" />
                    </Grid>
                </Grid>

                

                <Grid Grid.Row="8" Margin="0, 10, 0, 0">
                    <ListView SelectionMode="None" IsItemClickEnabled="True" caliburn:Message.Attach="[Event ItemClick] = [SelectImage($eventArgs)]"
                              ItemsSource="{Binding SearchedImages}" ItemContainerStyle="{StaticResource ImageListViewItemStyle}">
                        <ListView.ItemTemplate>
                            <DataTemplate>
                                <Image Margin="0" Source="{Binding Converter={StaticResource UriTo100x100BitmapConverter}}"
                                       Stretch="UniformToFill" HorizontalAlignment="Center" VerticalAlignment="Center" />
                            </DataTemplate>
                        </ListView.ItemTemplate>
                        <ListView.ItemsPanel>
                            <ItemsPanelTemplate>
                                <WrapGrid Orientation="Horizontal" ItemHeight="100" ItemWidth="100" />
                            </ItemsPanelTemplate>
                        </ListView.ItemsPanel>
                    </ListView>
                </Grid>

            </Grid>

            <Grid Grid.Column="1" Margin="20, 0, 0, 0">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                    </Grid.RowDefinitions>

                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="Search" Margin="0,-11,10,10" Style="{StaticResource DefaultApplicationGroupTitleStyle}" />
                            <ProgressRing IsActive="{Binding SearchInProgress}"  Margin="0,-8,0,0" Width="15" Height="15" />
                        </StackPanel>
                        <ComboBox ItemsSource="{Binding EntityTypes, Mode=OneWay}" Style="{StaticResource ComboBoxStyleNoBorder}" Grid.Column="1"
					SelectedItem="{Binding SelectedEntityType,Mode=TwoWay}" Margin="0,-5,0,0"/>
                    </Grid>

                    <TextBox Text="{Binding SearchTerms, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
					PlaceholderText="Search for what you need" Grid.Row="1" BorderBrush="{StaticResource DefaultApplicationBorderTileBrush}" />

                    <common:SelectListView x:Name="Entities" Grid.Row="2" SelectionMode="Multiple"
				        IsItemClickEnabled="False" ScrollViewer.HorizontalScrollBarVisibility="Disabled"
				        ScrollViewer.VerticalScrollBarVisibility="Auto" ItemContainerStyle="{StaticResource ListViewTrackStyle}">
                        <common:SelectListView.ItemsPanel>
                            <ItemsPanelTemplate>
                                <ItemsStackPanel Orientation="Vertical" HorizontalAlignment="Stretch" />
                            </ItemsPanelTemplate>
                        </common:SelectListView.ItemsPanel>
                    </common:SelectListView>
                </Grid>
            </Grid>

            <Grid Grid.Column="2" Margin="20, 0, 0, 0">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>

                    <TextBlock Text="Registration" Margin="0,-11,10,10" Style="{StaticResource DefaultApplicationGroupTitleStyle}" />

                    <common:SelectListView x:Name="SelectedEntities" SelectionMode="Multiple" Margin="0"
                    IsItemClickEnabled="False" ScrollViewer.HorizontalScrollBarVisibility="Disabled" Grid.Row="1"
				    ScrollViewer.VerticalScrollBarVisibility="Auto" ItemContainerStyle="{StaticResource ListViewTrackStyle}">
                        <common:SelectListView.ItemsPanel>
                            <ItemsPanelTemplate>
                                <ItemsStackPanel Orientation="Vertical" HorizontalAlignment="Stretch" />
                            </ItemsPanelTemplate>
                        </common:SelectListView.ItemsPanel>
                    </common:SelectListView>

                    <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Grid.Row="2" Margin="0, 10, 0, 0">
                        <Button Content="Accept" Width="100" x:Name="Accept" Style="{StaticResource DefaultTextButtonStyle}"
                            Foreground="{StaticResource DefaultApplicationForeground}"/>
                        <Button Content="Cancel" Width="100" x:Name="Cancel" Style="{StaticResource DefaultTextButtonStyle}"
                            Foreground="{StaticResource DefaultApplicationForeground}"/>
                    </StackPanel>
                </Grid>
            </Grid>


        </Grid>
    </Grid>
</Page>
